//
//  RootController.m
//  TestNav3
//
//  Created by pier on 12-5-28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "RootController.h"
#import "AContrller.h"
#import "CController.h"

@implementation RootController
@synthesize nav;
@synthesize customNav;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.
    //初始化或者push到navigaiton栈中的controller，该controller是可以release的
    //每个controller只能让一个navigation使用
    UIViewController *controller = [[[AContrller alloc] init] autorelease];
    self.nav = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease];
    
    UIViewController *controller2 = [[[CController alloc] init] autorelease];
    self.customNav = [[[UINavigationControllerCustom alloc] initWithRootViewController:controller2 barBackgroundImage:[UIImage imageNamed:@"title.png"]] autorelease];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.nav = nil;
    self.customNav = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [nav release];
    [customNav release];
    [super dealloc];
}

- (IBAction)addA:(id)sender {
//    UIViewController* view = self.nav.topViewController;
    [self.view addSubview:self.nav.view];
//    UIViewController *controller = [[[AContrller alloc] init] autorelease];
//    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
//    [self.view addSubview:nav.view];
}

- (IBAction)addCustomA:(id)sender {
//    UIViewController* view = self.customNav.topViewController;
    [self.view addSubview:self.customNav.view];
}

- (IBAction)modalA:(id)sender {
    [self presentModalViewController:self.nav animated:YES];
}

- (IBAction)modalCustomA:(id)sender {
     [self presentModalViewController:self.customNav animated:YES];
}
@end
